package com.eulog.gwt.axisdesign.propertyA.client;

import com.eulog.gwt.euloggwtlibrary.user.client.ui.MouseEventWidgetCollection;
import com.eulog.gwt.euloggwtlibrary.user.client.ui.SwitchingImage;
import com.extjs.gxt.ui.client.widget.layout.TableRowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.AdapterToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;

public class Navigation extends ToolBar {
	
	protected MouseEventWidgetCollection<SwitchingImage> naviSwitchingImages;
	
	public Navigation() {
		naviSwitchingImages = new MouseEventWidgetCollection<SwitchingImage>();

		SwitchingImage homeImage = new SwitchingImage(MasterRack.imageManager.navi01a,MasterRack.imageManager.navi01b,false,false,true,true);
		SwitchingImage galleryPhotoImage = new SwitchingImage(MasterRack.imageManager.navi02a,MasterRack.imageManager.navi02b,false,true,true,true);
		SwitchingImage propertyInfoImage = new SwitchingImage(MasterRack.imageManager.navi03a,MasterRack.imageManager.navi03b,false,true,true,true);
		SwitchingImage contactImage = new SwitchingImage(MasterRack.imageManager.navi04a,MasterRack.imageManager.navi04b,false,true,true,true);
		
		homeImage.addClickListener(naviSwitchingImages);
		galleryPhotoImage.addClickListener(naviSwitchingImages);
		propertyInfoImage.addClickListener(naviSwitchingImages);
		contactImage.addClickListener(naviSwitchingImages);
		
		homeImage.addMouseListener(naviSwitchingImages);
		galleryPhotoImage.addMouseListener(naviSwitchingImages);
		propertyInfoImage.addMouseListener(naviSwitchingImages);
		contactImage.addMouseListener(naviSwitchingImages);
		
		homeImage.setHyperLink(MasterRack.homeHistoryToken);
		galleryPhotoImage.setHyperLink(MasterRack.galleryPhotoHistoryToken);
		propertyInfoImage.setHyperLink(MasterRack.propertyInfoHistoryToken);
		contactImage.setHyperLink(MasterRack.contactHistoryToken);
		
		naviSwitchingImages.add(homeImage);
		naviSwitchingImages.add(galleryPhotoImage);
		naviSwitchingImages.add(propertyInfoImage);
		naviSwitchingImages.add(contactImage);
		
		init();
	}
	
	void init() {
		
		for (SwitchingImage switchingImage : naviSwitchingImages) {
			add(new AdapterToolItem(switchingImage));
		}
		
		layout();

	}
	
	protected void onRender(Element target, int index) {
		setElement(DOM.createDiv(), target, index);
		
		TableRowLayout layout = new TableRowLayout();
		layout.setCellSpacing(0);
		layout.setCellPadding(0);
		setLayout(layout);
		layout();
	}

}
